package com.topscomm.sys;

import com.topscomm.cbo.pojo.CboApprovalNodeInsEntity;
import com.topscomm.pub.util.DateUtil;
import com.topscomm.pub.util.I18nUtil;
import com.topscomm.pub.util.SpringUtil;
import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.pub.util.StringUtil;
import com.topscomm.tap.ITapService;
import com.topscomm.tap.TapEntity;
import com.topscomm.tap.TapScript;
import com.topscomm.tap.common.DatacodeCache;
import com.topscomm.tap.common.TapSystemConst.TapApprovalNodeStateEnum;

public class SysScript extends TapScript {
	/**
	 * 生成App消息推送内容
	 * @author: jiangtao
	 * @date: 2020年4月29日上午8:26:25
	 * @params: 
	 * @return_type: String
	 * @description:
	 * @modify:
	 */
	public String geneAppContentSubmitNew(ITapService service, TapEntity entity) {
        // 审批节点实例
        CboApprovalNodeInsEntity nodeins = (CboApprovalNodeInsEntity) entity;
        // 组织系统消息内容
        StringBufferProxy msg = new StringBufferProxy();
        DatacodeCache datacodeCache = (DatacodeCache)SpringUtil.getBean("datacodeCache");
        String dispName = datacodeCache.getValueDynamic("CboApprovalFlowCategory", nodeins.getSourcetype(), "code", "name");
        String maintitle = nodeins.getMaintitle();
        String extendfield2=nodeins.getExtendfield2();
        //maintitle只取时间字段
        if(!StringUtil.isEmpty(maintitle)) {
            int pos = maintitle.indexOf("于20");
            if(pos!=-1) {
                maintitle = maintitle.substring(pos+1, pos+11);
            }
        }
        if(StringUtil.isEmpty(dispName)) {
        	dispName="业务申请";
        }
		if (nodeins.getState() == TapApprovalNodeStateEnum.UnApproved) {
			msg.appendSingle("您于{0}提交的{1}单据在“{2}”阶段被驳回！",maintitle,dispName,extendfield2);
		} else {
			msg.appendSingle("您于{0}提交的{1}单据在“{2}”阶段审批通过！",maintitle,dispName,extendfield2);
		}
		return msg.toString();
	}
	
	/**
	 * 生成手机端系统消息主题
	 * @author: jiangtao
	 * @date: 2020年4月29日上午8:28:24
	 * @params: 
	 * @return_type: String
	 * @description:
	 * @modify:
	 */
	public String geneSysSubjectSubmitNew(ITapService service, TapEntity entity) {
	    StringBufferProxy msg = new StringBufferProxy();
        // 审批节点实例
        CboApprovalNodeInsEntity nodeins = (CboApprovalNodeInsEntity) entity;
        DatacodeCache datacodeCache = (DatacodeCache)SpringUtil.getBean("datacodeCache");
        String dispName = datacodeCache.getValueDynamic("CboApprovalFlowCategory", nodeins.getSourcetype(), "code", "name");
        if(StringUtil.isEmpty(dispName)) {
            dispName="业务申请";
        }
        msg.appendSingle("{0}通知", dispName);
	    return msg.toString();
	}
	
	/**
	 * 生成手机端系统消息内容
	 * @author: jiangtao
	 * @date: 2020年4月29日上午8:29:07
	 * @params: 
	 * @return_type: String
	 * @description:
	 * @modify:
	 */
	public String geneSysContentSubmitNew(ITapService service, TapEntity entity) {
        // 审批节点实例
        CboApprovalNodeInsEntity nodeins = (CboApprovalNodeInsEntity) entity;
        // 组织系统消息内容
        StringBufferProxy msg = new StringBufferProxy();
        DatacodeCache datacodeCache = (DatacodeCache)SpringUtil.getBean("datacodeCache");
        String dispName = datacodeCache.getValueDynamic("CboApprovalFlowCategory", nodeins.getSourcetype(), "code", "name");
        String maintitle = nodeins.getMaintitle();
        String extendfield2=nodeins.getExtendfield2();
        //maintitle只取时间字段
        if(!StringUtil.isEmpty(maintitle)) {
            int pos = maintitle.indexOf("于20");
            if(pos!=-1) {
                maintitle = maintitle.substring(pos+1, pos+11);
            }
        }
        if(StringUtil.isEmpty(dispName)) {
        	dispName="业务申请";
        }
		if (nodeins.getState() == TapApprovalNodeStateEnum.UnApproved) {
			msg.appendSingle("&nbsp;&nbsp;&nbsp;&nbsp;"+"您于{0}提交的{1}单据在“{2}”阶段被驳回！"+"<br>",maintitle,dispName,extendfield2);
		} else {
			msg.appendSingle("&nbsp;&nbsp;&nbsp;&nbsp;"+"您于{0}提交的{1}单据在“{2}”阶段审批通过！"+"<br>",maintitle,dispName,extendfield2);
		}
		String approvalopition = nodeins.getApprovalopinion();
		if (StringUtil.isEmpty(approvalopition)) {
			approvalopition = I18nUtil.getMessage("tap.common.not");
		}
		msg.appendSingle("&nbsp;&nbsp;&nbsp;&nbsp;"+I18nUtil.getMessage("tap.cboapprovalnode.approvalcomments")+":{0}<br>", approvalopition);
		msg.appendSingle("&nbsp;&nbsp;&nbsp;&nbsp;"+I18nUtil.getMessage("tap.date.senddate")+":{0}<br>", DateUtil.Now());
		return msg.toString();
	}
}
